package com.woniuxy.mallweb.exception;
import cn.hutool.http.HttpStatus;
import feign.FeignException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalException {
    /**
     * 异常则返回登录页面
     * @return
     */
//    @ExceptionHandler(FeignException.class)
//    public String noLogin(){
//        return "noLogin";
//    }

    @ExceptionHandler
    public String noLogin(FeignException e){
        log.info("noLogin is FeignException：{}",e);
        //未登录
        if(e.status()== HttpStatus.HTTP_UNAUTHORIZED){
            return "noLogin";
        } else if (e.status()== HttpStatus.HTTP_FORBIDDEN) {
            //禁止访问
            return "没用权限";
        }
        return "login";
    }
}
